package xuegao.study.mall.admin.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xuegao.study.mall.admin.feign.UmsResourceClient;
import xuegao.study.mall.common.api.CommonPage;
import xuegao.study.mall.common.api.CommonResult;
import xuegao.study.mall.common.model.ums.UmsResource;
import xuegao.study.mall.common.model.ums.UmsResourceCategory;

import java.util.List;

@RestController
@RequestMapping("/resource")
public class UmsResourceController {

    @Autowired
    private UmsResourceClient umsResourceClient;

    @GetMapping("/resourceCategory/listAll")
    public CommonResult<List<UmsResourceCategory>> listMenu(){
        return umsResourceClient.listMenu();
    }

    @ApiOperation("添加资源")
    @PostMapping("/create")
    public CommonResult<Integer> add(@RequestBody UmsResource umsResource) {
        return umsResourceClient.add(umsResource);
    }

    @GetMapping("/list")
    public CommonResult<CommonPage<UmsResource>> listResource(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
            @RequestParam(value = "nameKeyword", defaultValue = "") String nameKeyword,
            @RequestParam(value = "urlKeyword", defaultValue = "") String urlKeyword,
            @RequestParam(value = "categoryId", required = false) Long categoryId) {
        return umsResourceClient.listResource(pageNum, pageSize, nameKeyword, urlKeyword, categoryId);
    }

    @GetMapping("/listAll")
    public CommonResult<List<UmsResource>> listAll() {
        return umsResourceClient.listAll();
    }



    @PostMapping("/update/{id}")
    public CommonResult<Integer> update(@PathVariable("id") Long id, @RequestBody UmsResource umsResource) {
        return umsResourceClient.update(id, umsResource);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResult<Integer> deleteResource(@PathVariable("id") Long id) {
        return umsResourceClient.deleteResource(id);
    }

}
